<%@page import="java.sql.*"%>
<%@page import="model.DBAdapter"%>
<%@page import="jsp.ClassJSP"%>
<%@page import="model.Settings"%>

<%
	DBAdapter adapter = DBAdapter.getInstance();
	adapter.open();	
	ResultSet rs = null;
	String query = "";
	
	String className = "";
	int classId = -1;
	String classHTML = "<option value=\""+classId+"\">--Select Qucik Link--</option>";
	String quickLink1HTML = classHTML;
	String quickLink2HTML = classHTML;
	String quickLink3HTML = classHTML;
	String quickLink4HTML = classHTML;
	String quickLink5HTML = classHTML;
	String quickLink6HTML = classHTML;
	
	int quickLinkNumber =-1;
	int quickLink1Id = -1;
	int quickLink2Id = -1;
	int quickLink3Id = -1;
	int quickLink4Id = -1;
	int quickLink5Id = -1;
	int quickLink6Id = -1;
	
	int userLevel = -1;
	int selectedYear = 1977;
	
	try {
		selectedYear = ((Integer)session.getAttribute("selectedYear")).intValue();
		userLevel = ((Integer) session.getAttribute("userLevel")).intValue();
	} catch (Exception e) {
		response.sendRedirect("login.jsp");
	}
	
	try {
		
		query = "select quick_link_number, class_id, year from quick_link";
		rs = adapter.select(query);
		while(rs.next()) {
			quickLinkNumber = rs.getInt("quick_link_number");
			switch(quickLinkNumber) {
				case 1:
					quickLink1Id = rs.getInt("class_id");
					break;
				case 2:
					quickLink2Id = rs.getInt("class_id");
					break;
				case 3:
					quickLink3Id = rs.getInt("class_id");
					break;
				case 4:
					quickLink4Id = rs.getInt("class_id");
					break;
				case 5:
					quickLink5Id = rs.getInt("class_id");
					break;
				case 6:
					quickLink6Id = rs.getInt("class_id");
					break;
			}
		}
		
		query = "SELECT cl.class_id, cl.class_name FROM class cl, class_details cld where cl.class_id = cld.class_id  AND cld.year =" + selectedYear + " ORDER BY class_id"; 
		rs = adapter.select(query);
		while(rs.next()) {
			className = rs.getString("cl.class_name");
			classId = rs.getInt("cl.class_id");
			quickLink1HTML += "<option  "+(quickLink1Id==classId ? " selected=\"selected\"" : "")+" value=\""+classId+"\">"+ className+"</option>";
			quickLink2HTML += "<option "+(quickLink2Id==classId ? " selected=\"selected\"" : "")+" value=\""+classId+"\">"+ className+"</option>";
			quickLink3HTML += "<option "+(quickLink3Id==classId ? " selected=\"selected\"" : "")+" value=\""+classId+"\">"+ className+"</option>";
			quickLink4HTML += "<option "+(quickLink4Id==classId ? " selected=\"selected\"" : "")+" value=\""+classId+"\">"+ className+"</option>";
			quickLink5HTML += "<option "+(quickLink5Id==classId ? " selected=\"selected\"" : "")+" value=\""+classId+"\">"+ className+"</option>";
			quickLink6HTML += "<option "+(quickLink6Id==classId ? " selected=\"selected\"" : "")+" value=\""+classId+"\">"+ className+"</option>";
		}
	} catch (Exception e) {
		e.toString();
	}
	
	////////////////////////////////////////////////////////////////////////////
	//Code for the showing the year option tag.
	////////////////////////////////////////////////////////////////////////////
	int yearConfig = Settings.getInstance().getConfiguredYear();
	String yearHTML = new ClassJSP().getOptionTagList(adapter, yearConfig);
	
	adapter.close();
	String yearDisplay = selectedYear + "-" + (selectedYear+1);
	String addEditMessage = "Creating the Quick link for classes for year " + yearDisplay;
	
	
%>
<form method="post" action="" name="userForm" onsubmit="return saveQuickLink(this);">
<table cellpadding="0" width="100%" class="content" align="left">

<tr>
	<td width="10%" align="left">
		<table class="header" style="margin-bottom: -11px;"  align="left">
			<tr>
				<td valign="bottom" align="left">
					Quick Link
				</td>
			</tr>
		</table>
		
	</td>
	<td width="72%" align="center">
	<%=addEditMessage%>
	<input type="hidden" name="action" value="save" />
	
	</td>
	<td width="10%">
	<input id='save_bottom' onmouseover="return colorChangeTemporary('save_bottom');" onmouseout="return colorChangeUnDo('save_bottom');" type="submit" name = "save_bottom" value="Save" class="buttonSave">
		
	</td>
	<td width="10%">
		<input id='cancel_bottom' onmouseover="return colorChangeTemporary('cancel_bottom');" onmouseout="return colorChangeUnDo('cancel_bottom');" type="button" name = "cancel_bottom" value="Cancel" class="buttonCancel" onClick="loadContent('settings')">
		
	</td>
</tr>

<tr>
<td colspan="4">
		<table id="outline" cellspacing="5" width="100%">       			
				<tr>
			 		<td width="10%">
            			<label style="font-weight:bold;color:navy;">Quick Link 1:</label>
			        </td>   
			 		<td width="30%">
            			<select id="quickLink1" name="quickLink1" size="1" style="width: 205px;"/>
							<%=quickLink1HTML%>
					    </select>
			   		</td>   
			 		<td width="10%">
            			<label style="font-weight:bold;color:navy;">Quick Link 2:</label>
			        </td>   
			 		<td width="30%">
			 			<select id="quickLink2" name="quickLink2" size="1" style="width: 205px;"/>
							<%=quickLink2HTML%>
					    </select>
			      	</td>   
       			</tr>
       			<tr>
			 		<td width="100%" colspan="4">
            			&nbsp;
			      	</td>   
       			</tr>
       			
       			<tr>
			 		<td width="10%">
            			<label style="font-weight:bold;color:navy;">Quick Link 3:</label>
			        </td>   
			 		<td width="30%">
            			<select id="quickLink3" name="quickLink3" size="1" style="width: 205px;"/>
							<%=quickLink3HTML%>
					    </select>
			   		</td>   
			 		<td width="10%">
            			<label style="font-weight:bold;color:navy;">Quick Link 4:</label>
			        </td>   
			 		<td width="30%">
			 			<select id="quickLink4" name="quickLink4" size="1" style="width: 205px;"/>
							<%=quickLink4HTML%>
					    </select>
			      	</td>   
       			</tr>
       			<tr>
			 		<td width="100%" colspan="4">
            			&nbsp;
			      	</td>   
       			</tr>
       			
       			<tr>
			 		<td width="10%">
            			<label style="font-weight:bold;color:navy;">Quick Link 5:</label>
			        </td>   
			 		<td width="30%">
            			<select id="quickLink5" name="quickLink5" size="1" style="width: 205px;"/>
							<%=quickLink5HTML%>
					    </select>
			   		</td>   
			 		<td width="10%">
            			<label style="font-weight:bold;color:navy;">Quick Link 6:</label>
			        </td>   
			 		<td width="30%">
			 			<select id="quickLink6" name="quickLink6" size="1" style="width: 205px;"/>
							<%=quickLink6HTML%>
					    </select>
			      	</td>   
       			</tr>
       			<tr>
			 		<td width="100%" colspan="4">
            			&nbsp;
			      	</td>   
       			</tr>
			   	
		 	</table>
     	<br/>
</td>
</tr>	

<tr>
	<td width="80%" align="center" colspan="2">
	&nbsp;
	</td>
	<td width="10%">
	<input id='save' onmouseover="return colorChangeTemporary('save');" onmouseout="return colorChangeUnDo('save');" type="submit" name = "save" value="Save" class="buttonSave">
		
	</td>
	<td width="10%">
		<input id='cancel' onmouseover="return colorChangeTemporary('cancel');" onmouseout="return colorChangeUnDo('cancel');" type="button" name = "cancel" value="Cancel" class="buttonCancel" onClick="loadContent('settings')">
		
	</td>
</tr>

<!-- HTML for display the default year settings.. -->
<% if(userLevel == 1)  {%>
<tr>
	<td align="left" height="28px" colspan="4">
		<table class="header" style="margin-bottom: -11px;"  align="left">
			<tr>
				<td valign="bottom" align="left">
					Year Configuration
				</td>
			</tr>
		</table>
		
	</td>
</tr>
<tr>
<td colspan="4">
		<table id="outline" cellspacing="5" width="100%">       			
				<tr>
			 		<td width="10%">
            			<label style="font-weight:bold;color:navy;">Configured Year:</label>
			        </td>   
			 		<td width="30%">
            			<select id="yearConfig" name="yearConfig" size="1" style="width: 205px;"/>
							<%=yearHTML%>
					    </select>
			   		</td>   
			 		<td width="40%" colspan="2" align="left">
            			<input id='save' onmouseover="return colorChangeTemporary('save');" onmouseout="return colorChangeUnDo('save');" type="button" name = "save" value="Update" class="buttonSave" onClick="return updateConfiguredYear(this);">
			        </td>     
       			</tr>
       			
		 	</table>
     	<br/>
</td>
</tr>

<%} %>		
</table>
</form>

